
#line 1 "..\..\main.c" /0
  
#line 1 "D:\6.Embed\61-KEIL-ARM\C51\INC\reg52.h" /0






 
 
 
 
 
 
 sfr P0    = 0x80;
 sfr P1    = 0x90;
 sfr P2    = 0xA0;
 sfr P3    = 0xB0;
 sfr PSW   = 0xD0;
 sfr ACC   = 0xE0;
 sfr B     = 0xF0;
 sfr SP    = 0x81;
 sfr DPL   = 0x82;
 sfr DPH   = 0x83;
 sfr PCON  = 0x87;
 sfr TCON  = 0x88;
 sfr TMOD  = 0x89;
 sfr TL0   = 0x8A;
 sfr TL1   = 0x8B;
 sfr TH0   = 0x8C;
 sfr TH1   = 0x8D;
 sfr IE    = 0xA8;
 sfr IP    = 0xB8;
 sfr SCON  = 0x98;
 sfr SBUF  = 0x99;
 
 
 
 sfr T2CON  = 0xC8;
 sfr RCAP2L = 0xCA;
 sfr RCAP2H = 0xCB;
 sfr TL2    = 0xCC;
 sfr TH2    = 0xCD;
 
 
 
 
 sbit CY    = PSW^7;
 sbit AC    = PSW^6;
 sbit F0    = PSW^5;
 sbit RS1   = PSW^4;
 sbit RS0   = PSW^3;
 sbit OV    = PSW^2;
 sbit P     = PSW^0;  
 
 
 sbit TF1   = TCON^7;
 sbit TR1   = TCON^6;
 sbit TF0   = TCON^5;
 sbit TR0   = TCON^4;
 sbit IE1   = TCON^3;
 sbit IT1   = TCON^2;
 sbit IE0   = TCON^1;
 sbit IT0   = TCON^0;
 
 
 sbit EA    = IE^7;
 sbit ET2   = IE^5;  
 sbit ES    = IE^4;
 sbit ET1   = IE^3;
 sbit EX1   = IE^2;
 sbit ET0   = IE^1;
 sbit EX0   = IE^0;
 
 
 sbit PT2   = IP^5;
 sbit PS    = IP^4;
 sbit PT1   = IP^3;
 sbit PX1   = IP^2;
 sbit PT0   = IP^1;
 sbit PX0   = IP^0;
 
 
 sbit RD    = P3^7;
 sbit WR    = P3^6;
 sbit T1    = P3^5;
 sbit T0    = P3^4;
 sbit INT1  = P3^3;
 sbit INT0  = P3^2;
 sbit TXD   = P3^1;
 sbit RXD   = P3^0;
 
 
 sbit SM0   = SCON^7;
 sbit SM1   = SCON^6;
 sbit SM2   = SCON^5;
 sbit REN   = SCON^4;
 sbit TB8   = SCON^3;
 sbit RB8   = SCON^2;
 sbit TI    = SCON^1;
 sbit RI    = SCON^0;
 
 
 sbit T2EX  = P1^1;  
 sbit T2    = P1^0;  
 
 
 sbit TF2    = T2CON^7;
 sbit EXF2   = T2CON^6;
 sbit RCLK   = T2CON^5;
 sbit TCLK   = T2CON^4;
 sbit EXEN2  = T2CON^3;
 sbit TR2    = T2CON^2;
 sbit C_T2   = T2CON^1;
 sbit CP_RL2 = T2CON^0;
 
 
#line 1 "..\..\main.c" /0
 
 


 
 typedef unsigned int uint;	 
 typedef unsigned char uchar;


 
 sfr T2MOD = 0xC9;
 
 
 sbit S4 = P3^3;
 sbit S5 = P3^2;
 sbit S6 = P3^1;
 sbit S7 = P3^0;
 
 
 
 uchar Dsp_Code[] = {0xc0,	0xf9,	0xa4,	0xb0,	0x99,	0x92,	0x82,	0xf8,	0x80,	0x90,	0xff,	0xBF,	0x8c,	0x89,	0x8e};
 
 uchar Dsp_Bit[8]={10,10,10,10,10,10,10,10};
 
 
 uchar Dsp_Point[9]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
 
 
 enum PERIPHERAL
 {
 LED = 0x80,
 DEVICE = 0xa0,
 BIT = 0xc0,
 SEG = 0xe0
 };
 
 typedef enum
 {
 UNPRESS = 0, 
 S4_PRESS = 4, 
 S5_PRESS, 
 S6_PRESS, 
 S7_PRESS 
 }KeyEvent_TypeDef;
 
 
 
 uint	Tick;
 
 uchar dsp_com;
 





 
 void Timer2_Init(void)		 
 {
 T2MOD = 0;				 
 T2CON = 0;				 
 TL2 = 0x18;				 
 TH2 = 0xFC;				 
 RCAP2L = 0x18;			 
 RCAP2H = 0xFC;			 
 TR2 = 1;				 
 TF2 = 0;
 
 ET2 = 1;
 EA = 1;
 }
 
 
 
 void Timer2_Rountine() interrupt 5           
 {
 TF2 = 0;				 
 
 Tick++;
 }
 








 
 KeyEvent_TypeDef KeyScan(void)
 {
 
 static uchar S4_value = 0xFF;
 static uchar S5_value = 0xFF;
 static uchar S6_value = 0xFF;
 static uchar S7_value = 0xFF;
 static uchar lock = 0;
 
 
 
 S4_value <<= 1;
 S4_value |= S4;
 S5_value <<= 1;
 S5_value |= S5;
 S6_value <<= 1;	
 S6_value |= S6;
 S7_value <<= 1;
 S7_value |= S7;
 
 if((!S4_value||!S5_value||!S6_value||!S7_value) && !lock)	 
 {
 lock = 1;				 
 if(!S4_value)
 return S4_PRESS;
 else if(!S5_value)
 return S5_PRESS;
 else if(!S6_value)
 return S6_PRESS;
 else if(!S7_value)
 return S7_PRESS;
 }
 else if(S4_value && S5_value && S6_value && S7_value && lock)			 
 {
 lock = 0;													
 }
 else{																	 
 }
 
 return UNPRESS;  
 }





 
 void LED_Flow_Task(void)
 {
 static uint LED_Tick;
 static uchar State = 0;
 
 if((Tick - LED_Tick) > 500)
 {	
 LED_Tick = Tick;
 
 switch (State)                 
 {
 case 0:
  P0=~(1<<State);P2=LED;P2=0;
  P0=1<<4;P2=DEVICE;P2=0;
 State = 1;
 break;
 case 1:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 2;
 break;
 case 2:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 3;            
 break;
 case 3:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 4;    
 break;
 case 4:
  P0=~(1<<State);P2=LED;P2=0;
  P0=1<<6;P2=DEVICE;P2=0;
 State = 5;
 break;
 case 5:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 6;
 break;
 case 6:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 7;
 break;
 case 7:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 0;
 break;
 default:
 break;	
 }
 }
 }





 
 void P_Init(void)				 
 {
  P0=0xff;P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
  P0=0x00;P2=BIT;P2=0;
  P0=0xff;P2=SEG;P2=0;
 
 Timer2_Init(); 
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 





 
 void Key_Task(void)
 {
 static uint Key_Tick;							
 
 if((Tick - Key_Tick) > 2)
 {
 Key_Tick = Tick;
 switch (KeyScan())
 {
 case UNPRESS:
 break;
 case S4_PRESS:
 if(++dsp_com > 7)
 dsp_com = 0;
 break;
 case S5_PRESS:
 
 break;
 case S6_PRESS:
 
 break;
 case S7_PRESS:
 
 break;
 
 default:
 break;
 }			
 }
 }	
 
 


 
 void main(void)
 {
 
 P_Init();
 Dsp_Bit[0] = 0;
 Dsp_Bit[1] = 1;
 Dsp_Bit[2] = 2;
 Dsp_Bit[3] = 3;
 Dsp_Bit[4] = 4;
 Dsp_Bit[5] = 5;
 Dsp_Bit[6] = 6;
 Dsp_Bit[7] = 7;
 
 while(1)
 {
 
 LED_Flow_Task();
 Key_Task();
 
 
  P0=Dsp_Code[Dsp_Bit[dsp_com]];P2=SEG;P2=0;		 
  P0=1<<dsp_com;P2=BIT;P2=0;				 
 }        
 }
